﻿using Microsoft.Office.Interop.Excel;
using System;

namespace TecBaseObjects.Base {
    
    public class TpAccountingSourceRow {

        #region Members

        private Range myRow;

        #endregion

        #region Constructor

        public TpAccountingSourceRow(Range row) {
            this.myRow = row;
        }

        #endregion

        #region Properties

        public int AccountNo {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "A"];
                if (r1.Value != null) {
                    if (Int32.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public int ContraAccountNo {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "E"];
                if (r1.Value != null) {
                    if (Int32.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double Credit {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "G"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public double Debit {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "F"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public bool IsEmpty {
            get{
                bool ret = false;
                Range r1 = myRow.Cells[1, "A"];
                if (r1.Value == null) {
                    return true;
                }
                string t1 = Convert.ToString(r1.Value);
                if (t1.Length == 0) {
                    return true;
                }
                return ret;
                }
        }

        public double Tax {
            get {
                double ret = 0.0;
                Range r1 = myRow.Cells[1, "H"];
                if (r1.Value != null) {
                    if (Double.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public int TaxKey {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "I"];
                if (r1.Value != null) {
                    if (Int32.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public string Text {
            get {
                string ret ="";
                Range r1 = myRow.Cells[1, "D"];
                if (r1.Value != null) {
                    ret = Convert.ToString(r1.Value);
                }
                return ret;
            }
        }

        public DateTime VoucherDate {
            get {
                DateTime ret = new DateTime(1900, 1, 1);
                Range r1 = myRow.Cells[1, "B"];
                if (r1.Value != null) {
                    if (DateTime.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        public int VoucherNo {
            get {
                int ret = 0;
                Range r1 = myRow.Cells[1, "C"];
                if (r1.Value != null) {
                    if (Int32.TryParse(r1.Value.ToString(), out ret)) {
                        return ret;
                    }
                }
                return ret;
            }
        }

        #endregion

    }
}
